<template>
	<view class="active-pages pages">
		<CustomNav title="我的奖品" :normal="{textColor:'#fff',background:'linear-gradient(to right, #FF2F34, #FF6B18)'}"
			:is-back="true"></CustomNav>
		<view class="list-block">
			<view class="tips">请确保您有默认收货地址，防止发货失败！</view>
			<template v-if="list.length>0">
				<view class="info-item" v-for="item in list" :key="item.id">
					<view class="left-item">
						<view class="name">{{item.hitPrize}}</view>
						<view class="time" style="margin-bottom: 20rpx;">中奖时间：{{item.drawTime}}</view>
						<view v-if="item.type==1&&item.isSend ==1" class="time" style="margin-bottom: 20rpx;">失效时间：
						{{item.effectiveTime}}
						</view>
						<view v-if="item.type==1&&item.isSend ==1" class="time" style="margin-bottom: 20rpx;">领取对象：
						<template v-if="item.bussesType!=null&&item.bussesType==0">赋能店</template>
						<template v-if="item.bussesType!=null&&item.bussesType==1">{{item.bussinessName}}</template>
						</view>
						<view v-if="item.type==1&&item.isSend ==1" class="time" style="margin-bottom: 20rpx;">领取地址：
						<template v-if="item.address!=null">{{item.address}}</template>
						</view>
						<view style="display: flex;justify-content: space-between;width: 100%;">
							<view class="time" v-if="item.isSend ==1" style="color: #F26F30;">未发放
							</view>
							<view class="time" v-if="item.isSend ==2" style="color: #09C15F;">已发放</view>
							<view class="time" v-if="item.isSend ==3" style="color: #09C15F;">待收货</view>
							<view class="step" @click="receive(item.id)" v-if="item.type==1&&item.isSend ==1">领取
							</view>
						</view>
					</view>
				</view>
			</template>
			<view v-if="more==false&&list.length==0" class="empty">暂无数据</view>
			<view v-else-if="more==false&&list.length>0" class="empty">没有更多了</view>
		</view>
	</view>
</template>

<script>
	import {
		getRecordApi,
		receivedGoods
	} from '@/api/shopping.js'
	import {
		isMore
	} from '@/util/util'
	export default {
		data() {
			return {
				conf: {
					page: 1,
					limit: 10,
				},
				more: true,
				list: []
			}
		},
		methods: {
			receive(id) {
				var that = this;
				uni.showModal({
					title: '提示',
					content: '请确保您已拿到商品再进行此操作',
					cancelText: '未领取',
					confirmText: '已领取',
					success(res) {
						
						if (res.confirm) {
							uni.showLoading({
								title: '加载中',
								mask: true
							})
							receivedGoods({
								id: id
							}).then(res => {
								uni.showToast('领取成功')
								that.getList(true)
							})
						}
					}
				})

			},
			handleRefresh() {
				this.conf.page = 1;
				this.more = true
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				this.getList(true)
			},
			getList(refresh = false) {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				getRecordApi({
					activityId: this.id,
					page: this.conf.page,
					limit: this.conf.limit,
				}).then((res) => {
					let list = res.list || [];
					if (refresh) {
						this.list = list;

					} else {
						this.list = [...this.list, ...list]
					}
					this.more = isMore(this.conf.page, this.conf.limit, res.count)
				})
			},
		},
		onPullDownRefresh() {
			this.handleRefresh();
		},
		onReachBottom() {
			if (this.more) {
				this.conf.page++;
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				this.getList();
			}
		},
		onLoad(e) {
			this.id = e.id
			this.getList(true);
		}
	}
</script>

<style lang="scss" scoped>
	.active-pages {
		overflow: hidden;

		.list-block {
			margin-top: 180rpx;
			padding: 30rpx;
			position: relative;

			.tips {
				padding: 30rpx;
				background-color: #FEF3EF;
				color: #FF3B2F;
				border-radius: 20rpx;
				margin-bottom: 20rpx;
				font-size: 28rpx;
			}

			.info-item {
				background-color: #fff;
				border-radius: 20rpx;
				margin-bottom: 20rpx;
				padding: 30rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.left-item {
					width: 100%;

					.name {
						font-size: 32rpx;
						margin-bottom: 20rpx;
					}

					.time {
						font-size: 28rpx;
						color: #767676;
					}

					.step {
						width: 140rpx;
						height: 50rpx;
						display: flex;
						border-radius: 60rpx;
						justify-content: center;
						align-items: center;
						color: #FF2F34;
						border: 1px solid #FF2F34;
						font-size: 26rpx;
					}
				}

				.score {
					color: #39AA3F;
					font-size: 32rpx;
				}
			}

			.empty {
				display: flex;
				justify-content: center;
			}
		}
	}
</style>